﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Entities.Validation;
using NetROS.Tiers.Services;
using NetRosApp.Infrastructure.Interface.Services;

namespace NetRosApp.Klijenti
{
    //public class BaseEditorPresenter<T> : Presenter<T>, IBaseEditorPresenter where T : IBaseEditorView 
    //{
    public class BaseEditorPresenter<T> : Infrastructure.Interface.Base.BaseViews.BaseEditorPresenter<T>, IBaseEditorPresenter where T : IBaseEditorView 
    {

      //  internal bool _changed = true;
      //  protected internal new string _pozvano = "None";

//        EventHandler<EventArgs<object, string>> delegata;
//        public event EventHandler<EventArgs<object, string>> OnDodatniPozivi
//        {
//            add
//            {
//                delegata += value;
//            }
//            remove
//            {
//                delegata -= value;
//            }
//        }
//        public void OpenEditorNewOrEditinTab(object Entity, Type EditorClass)
//        {
//            WorkItem.EventTopics[EventTopicNames.OpenCreateView].Fire(this.View, new EventArgs<object, object, object, object, WorkItem>(EditorClass, Entity, null, null, WorkItem.Parent), WorkItem, PublicationScope.Global);
//        }

//        public virtual void CreateNewEntity()
//        {
//            WorkItem.Services.Get<IExpUtil>().HandleException(new Exception("Nedefinirani način. CreateNewEntity"));
//        }

//        public virtual bool SaveData()
//        {
//            WorkItem.Services.Get<IExpUtil>().HandleException(new Exception("Nedefinirani način. SaveData"));
//            return false;
//        }

//        public virtual bool ZapisiData()
//        {
//            WorkItem.Services.Get<IExpUtil>().HandleException(new Exception("Nedefinirani način.  ZapisiData"));
//            return false;
//        }
//        public virtual bool ObrisiData()
//        {
//            WorkItem.Services.Get<IExpUtil>().HandleException(new Exception("Nedefinirani način.  ZapisiData"));
//            return false;
//        }

//        public virtual void OnCloseView()
//        {
//            //try
//            //{
//            //    base.CloseView();
//            //}
//            //catch
//            //{
//            //}
//            //WorkItem.Items.Remove(this.View);
//            //WorkItem.Items.Remove(this);
//            try
//            {
//                if (View.SmartPartView == WorkItem.Workspaces[WorkspaceNames.RightWorkspace].ActiveSmartPart)
//                {
//                    int index = WorkItem.Workspaces[WorkspaceNames.RightWorkspace].SmartParts.IndexOf(WorkItem.Workspaces[WorkspaceNames.RightWorkspace].ActiveSmartPart);
//                    if (index - 1 >= 0)
//                    {
//                        WorkItem.Workspaces[WorkspaceNames.RightWorkspace].Activate(WorkItem.Workspaces[WorkspaceNames.RightWorkspace].SmartParts[index - 1]);
//                    }
//                }
                
//                WorkItem.Terminate();
//            }
//            catch 
//            {
//                //System.Windows.Forms.MessageBox.Show(ex.Message.ToString());
//            }

//        }
//        public bool Changed
//        {
//            get { return _changed; }
//        }


//        //public virtual void SearchForEntity()
//        //{
//        //    throw new Exception("Nedefinirani način");
//        //}

//        #region Base Subscriptions
//        [EventSubscription(EventTopicNames.CloseActiveViewInRightWorkspace, ThreadOption.UserInterface)]
//        public void OnCloseActiveViewInRightWorkspace(object sender, EventArgs<bool, object> eventArgs)
//        {//TODO: Add your code here
//            if (eventArgs.Data || View.IsFocused() || object.Equals(eventArgs.Data1, View))
//            {
//                if (_changed)
//                {
//                    if (DevExpress.XtraEditors.XtraMessageBox.Show("Ima promjena.\n Prekinuti unos i zatvoriti?", "Pitanje", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
//                    {
//                        OnCloseView();
//                    }
//                }
//                else
//                {
//                    OnCloseView();
//                }
//            }
//        }

//        [EventSubscription(EventTopicNames.EntityItemChanged, ThreadOption.Publisher)]
//        public void OnEntityItemChanged(object sender, EventArgs<object, string> eventArgs)
//        {
//         if (eventArgs.Data1 == "Entity" && _pozvano == "None")

//                {
//                    Prikazi(eventArgs.Data);
//                    View.SetIzvjestajButtonEnabled = true;
//                }
            
//            if (_pozvano != "None")
//            {
//                if (delegata != null)
//                {
//                        delegata(this, new EventArgs<object,string>(eventArgs.Data,_pozvano));
//                     //   WorkItem.Services.Get<NetRosApp.Infrastructure.Interface.Services.IExpUtil>().HandleException(new Exception(delegata.GetInvocationList().Length.ToString()));

//                }

//            }
//            if (eventArgs.Data1 != "Entity" && _pozvano == "None")
//            {
//                if (delegata != null)
//                {
//                    delegata(this, new EventArgs<object, string>(eventArgs.Data, eventArgs.Data1));
//                }
//            }

//        }

//        public virtual void Prikazi(object Entity)
//    {

//                    WorkItem.Services.Get<IExpUtil>().HandleException(new Exception("Nedefinirani način. Prikazi"));
////                   View.Tip.Tip = BaseEditorView.TipEditora.TipEditoraEnum.PonovniPrikaz;
//    }

//        public void ShowModalSearch(object EntityToSearch, Type SearcherClass, object Parameters)
//        {

//            WindowSmartPartInfo wspi = new WindowSmartPartInfo();

//            wspi.Modal = true;

//            WorkItem.EventTopics[EventTopicNames.OpenCreateViewModal].Fire(this, new EventArgs<WorkItem, object, object, WindowSmartPartInfo, object>(WorkItem, SearcherClass, EntityToSearch, wspi, Parameters), WorkItem, PublicationScope.Global);
            
//        }

         public bool DozvolaZa(string Kljuc)
        {
            return WorkItem.Services.Get<IActionCatalogService>().CanExecute(Kljuc);
        }

        internal static Dokument GetHasStorno(Dokument Entity,int StornoTip)
        {
            //if (Entity != null)
            //{
            //    if (_dokumentService == null)
            //        _dokumentService = base.WorkItem.Services.Get<DokumentService>();

            //    TList<Dokument> TlStorno = _dokumentService.GetHasStorno(Entity.ID, StornoTip);
            //    if (TlStorno.Count == 0)
            //    {
            //        return null;
            //    }
            //    else
            //    {
            //        return TlStorno[0];
            //    }
            //}
            //return null;
            return null;
        }



        private DokumentService _dokumentService;

        private DjelatnikService _djelatnikService;

        private VezaService _vezaService;
        private ArtiklService _artiklService;
       



        

        public Dokument Storno(Dokument Entity, int StornoTip)
        {
            return Storno(Entity,StornoTip,String.Empty,String.Empty);
        }

        public Dokument Storno(Dokument Entity, int StornoTip,String Caption,String UOznaci)
        {
            if (Caption == String.Empty)
            {
                Caption = "Storno?";
            }
            if (UOznaci == String.Empty)
            {
                UOznaci = "Storniranje {0}";
            }
            if (Entity.IsNew) return null;

            if (Entity.IDDokumentTip == StornoTip) return null;

            Dokument result;



            if (_dokumentService == null)
                _dokumentService = WorkItem.Services.Get<DokumentService>();
            if (_vezaService == null)
                _vezaService = WorkItem.Services.Get<VezaService>();


            //TList<Dokument> BezVeze = _dokumentService.Get_Bez_Veze();
            //if (_dokumentService.GetHasStorno(Entity.ID,StornoTip).Count == 0 && _dokumentService.Get_Bez_Veze_ID(Entity.ID).Count != 0)
            //{
            if (DevExpress.XtraEditors.XtraMessageBox.Show(Caption, Caption, System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) return null;

            if (_djelatnikService == null)
                _djelatnikService = WorkItem.Services.Get<DjelatnikService>();
            if (_artiklService == null)
                _artiklService = WorkItem.Services.Get<ArtiklService>();
            // TList<Dokument> _dokumentList = _dokumentService.Get_Bez_Veze(); 

            Dokument StornoDokument = new Dokument();

            Dokument parentDokument = Entity;
            StornoDokument.Oznaka = String.Format(UOznaci, Entity.Oznaka);
            StornoDokument.Datum = DateTime.Now;
            StornoDokument.IDOrganizacijaOd = Entity.IDOrganizacijaOd;
            StornoDokument.IDOrganizacijaOdSource = Entity.IDOrganizacijaOdSource;
            StornoDokument.DatumDo = Entity.DatumDo;
            StornoDokument.IDOrganizacijaPrema = Entity.IDOrganizacijaPrema;
            StornoDokument.PorezNabavneVrijednosti = Entity.PorezNabavneVrijednosti;
            StornoDokument.IDDokumentTip = StornoTip;
            //reverspovrat.IDDokumentTipSource = _dokumentTipService.GetByID((int)DokumentTipList.Međuskladišnica_Primljena_Robno);
            StornoDokument.DateCreated = DateTime.Now;
            StornoDokument.DateModified = DateTime.Now;
            Djelatnik currentdjelatnik = _djelatnikService.GetByNaziv(Thread.CurrentPrincipal.Identity.Name);
            StornoDokument.IDUserIzdaoSource = currentdjelatnik;
            StornoDokument.IDUserIzdao = currentdjelatnik.ID;
            StornoDokument.IDKlijent = Entity.IDKlijent;
            StornoDokument.IDKlijentSource = Entity.IDKlijentSource;
            StornoDokument.NabavnaVrijednost = Entity.NabavnaVrijednost;
            StornoDokument.Napomena = Entity.Napomena;
            StornoDokument.Napomena2 = Entity.Napomena2;
            StornoDokument.IDNacinTransporta = Entity.IDNacinTransporta;
            StornoDokument.IDValute = Entity.IDValute;
            StornoDokument.IDNacinPlacanja = Entity.IDNacinPlacanja;
            StornoDokument.VezaDokumenta = Entity.Oznaka;
            StornoDokument.IDOrganizacijaZiroRacun = Entity.IDOrganizacijaZiroRacun;

            foreach (DokumentStavka tmpstav in Entity.DokumentStavkaCollection)
            {

                DokumentStavka nova = new DokumentStavka();

                nova.IDArtikl = tmpstav.IDArtikl;
                if (nova.IDArtikl != null)
                    nova.IDArtiklSource = _artiklService.DeepLoadByID(nova.IDArtikl.Value, true, NetROS.Tiers.Data.DeepLoadType.IncludeChildren, typeof(ArtiklMjera));
                nova.Kolicina = tmpstav.Kolicina;
                nova.Kolicina2 = tmpstav.Kolicina2;
                nova.Kolicina3 = tmpstav.Kolicina3;
                nova.Vrijednost = tmpstav.Vrijednost;
                nova.Vrijednost2 = tmpstav.Vrijednost2;
                nova.Vrijednost3 = tmpstav.Vrijednost3;
                nova.Postotak = tmpstav.Postotak;
                nova.IDValuta = tmpstav.IDValuta;
                nova.IDValuta2 = tmpstav.IDValuta2;
                nova.IDOrgJedOd = tmpstav.IDOrgJedOd;
                nova.Vrijednost4 = tmpstav.Vrijednost4;
                nova.Postotak2 = tmpstav.Postotak2;
                nova.Postotak3 = tmpstav.Postotak3;
                nova.Postotak4 = tmpstav.Postotak4;
                nova.Postotak5 = tmpstav.Postotak5;
                nova.Prilagoden = tmpstav.Prilagoden;
                nova.PrilagodenJedMj = tmpstav.PrilagodenJedMj;
                StornoDokument.DokumentStavkaCollection.Add(nova);
            }

                foreach (DokumentZaglavlje tmpstav in Entity.DokumentZaglavljeCollection)
            {

                DokumentZaglavlje nova = new DokumentZaglavlje();

                nova.FormatString = tmpstav.FormatString;
                nova.FormatTip = tmpstav.FormatTip;
                nova.IDSpecTip = tmpstav.IDSpecTip;
                nova.Vrijednost = tmpstav.Vrijednost;
                nova.Kolona = tmpstav.Kolona;
                nova.TekstZaglavlja = tmpstav.TekstZaglavlja;
                nova.RedBr = tmpstav.RedBr;
                StornoDokument.DokumentZaglavljeCollection.Add(nova);
            }


            foreach (DokumentDodatak tmpstav in Entity.DokumentDodatakCollection)
            {

                DokumentDodatak nova = new DokumentDodatak();
                nova.Opis = tmpstav.Opis;
                nova.Iznos = tmpstav.Iznos;
                StornoDokument.DokumentDodatakCollection.Add(nova);
            }

            foreach (DokumentPlacanje tmpstav in Entity.DokumentPlacanjeCollection)
            {

                DokumentPlacanje nova = new DokumentPlacanje();
                nova.Uplaceno = tmpstav.Uplaceno;
                nova.Datum = tmpstav.Datum;
                nova.IDNacinPlacanja = tmpstav.IDNacinPlacanja;
                StornoDokument.DokumentPlacanjeCollection.Add(nova);
            }

            Veza novaveza = new Veza();

            //bool result2 = _dokumentService.DeepSave(StornoDokument, NetROS.Tiers.Data.DeepSaveType.IncludeChildren, typeof(TList<DokumentStavka>));
            novaveza.IDParent = parentDokument.ID;
            novaveza.IDChild = StornoDokument.ID;
            StornoDokument.VezaCollectionGetByIDChild.Add(novaveza);
            //StornoDokument.VezaDokumenta = Entity.Oznaka;
            //   _vezaService.Save(novaveza);

            //  View.Tip.Tip = BaseEditorView.TipEditora.TipEditoraEnum.Storno;

            //int? IDZapisa = null;
            //_dokumentService.Zapisi(StornoDokument.ID, ref IDZapisa);
            result = StornoDokument;
            return result;
        }


        public bool ZapisiData(Dokument entity)
        {
            return ZapisiData(entity, false);
        }

        

        public bool ZapisiData(Dokument entity,bool skipispis)
        {
            if (_dokumentService == null)
                _dokumentService = WorkItem.Services.Get<DokumentService>();

            bool result = SaveData();
            List<DokumentStavka> _ltds = new List<DokumentStavka>();
            if (entity.IDDokumentTip == (int)DokumentTipList.Narudžba || entity.IDDokumentTip == (int)DokumentTipList.VisakManjak)
            {
                foreach (DokumentStavka _tmpdoc in entity.DokumentStavkaCollection)
                {
                    if (_tmpdoc.Kolicina == 0)
                    {
                        _tmpdoc.MarkToDelete();
                        _ltds.Add(_tmpdoc);
                     
                    }
                }
                result = SaveData();
                
                
                if (result )
                {
                    foreach (DokumentStavka _stavka in _ltds)
                {
                    entity.DokumentStavkaCollection.Remove(_stavka);
                }
                }
            }

         
         
            

            if (result)
            {
                int? IDZapisa = 0;
                IDataReader _dataReader = _dokumentService.Zapisi(entity.ID, ref IDZapisa);
                DataSet tmpset = null;
                if (_dataReader != null)
                {
                     tmpset = NetROS.Tiers.Data.Utility.ConvertDataReaderToDataSet(_dataReader);
                    _dataReader.Close();
                }

                if (tmpset != null && tmpset.Tables[0].Rows.Count == 0 && (entity.IDStatus == 0 || (entity.IDStatus == 1 && entity.IDDokumentTip == 51)))
                {
                    result = true;
                    if (!skipispis)
                    {
                        if (
                            DevExpress.XtraEditors.XtraMessageBox.Show("Ispisati?", "Ispis",
                                                                       System.Windows.Forms.MessageBoxButtons.YesNo,
                                                                       System.Windows.Forms.MessageBoxIcon.Question) ==
                            System.Windows.Forms.DialogResult.Yes)
                        {
                            Dokument _locdoc = _dokumentService.GetByID(entity.ID);
                            Dokument prikazi = (Dokument) _locdoc.Clone();
                            if (_locdoc != null)
                                ShowReportForDokumentTip(_locdoc);
                            Prikazi(prikazi);
                            return false;
                        }
                    }

                }
                else
                {
                    foreach (DataRow _tmpRow in tmpset.Tables[0].Rows)
                    {
                        TList<DokumentStavka> _dspoartiklu = null;
                        try
                        {
                            int i2 = Convert.ToInt32(_tmpRow["IDArtikl"]);   // Error
                            //_dspoartiklu = entity.DokumentStavkaCollection.FindAll("IDArtikl", _tmpRow["IDArtikl"]);
                            _dspoartiklu = entity.DokumentStavkaCollection.FindAll(DokumentStavkaColumn.IDArtikl,Convert.ToInt32(_tmpRow["IDArtikl"]));
                        }
                        catch (Exception e)
                        {

                            _dspoartiklu = entity.DokumentStavkaCollection.FindAll("Prilagoden", _tmpRow["IDArtikl"]);
                        }
                        
                            if (_dspoartiklu.Count != 0)
                            {
                                DokumentStavka _dspoartorg = _dspoartiklu.Find("IDOrgJedOd", Convert.ToInt32(_tmpRow["IDOrgJedOd"]));
                             
                                if (entity.IDDokumentTip == (int)DokumentTipList.VisakManjak)
                                {
                                    if (_dspoartorg != null)
                                    {
                                        ValidationRuleArgs _loc = new ValidationRuleArgs("Manjak");
                                        _loc.Tag = 0;
                                        _dspoartorg.AddValidationRuleHandler((delegate(object target, ValidationRuleArgs e)
                                        {
                                            if ((int)e.Tag == 0)
                                            {
                                                e.Description = "Greška nedovoljna količina";
                                                _loc.Tag = (int)_loc.Tag + 1;
                                                return false;
                                            }
                                            else
                                            {
                                                return true;
                                            }
                                        }
                                            ), _loc);


                                        _dspoartorg.Validate();

                                    }
                                }
                                else
                                {
                                    if (_dspoartorg != null)
                                    {
                                        ValidationRuleArgs _loc = new ValidationRuleArgs("Kolicina");
                                        _loc.Tag = 0;
                                        _dspoartorg.AddValidationRuleHandler((delegate(object target, ValidationRuleArgs e)
                                        {
                                            if ((int)e.Tag == 0)
                                            {
                                                e.Description = "Greška nedovoljna količina";
                                                _loc.Tag = (int)_loc.Tag + 1;
                                                return false;
                                            }
                                            else
                                            {
                                                return true;
                                            }
                                        }
                                            ), _loc);
                                        _dspoartorg.Validate();

                                    }
                                }
                            }
                            else
                            {

                                _dspoartiklu = entity.DokumentStavkaCollection.FindAll("IDOrgJedOd", _tmpRow["IDOrgJedOd"]);
                                DokumentStavka _dspoartorg = _dspoartiklu.Find("Vrijednost3", _tmpRow["Vrijednost3"]);
                                if (entity.IDDokumentTip == (int)DokumentTipList.VisakManjak)
                                {
                                    if (_dspoartorg != null)
                                    {
                                        ValidationRuleArgs _loc = new ValidationRuleArgs("Manjak");
                                        _loc.Tag = 0;
                                        _dspoartorg.AddValidationRuleHandler((delegate(object target, ValidationRuleArgs e)
                                        {
                                            if ((int)e.Tag == 0)
                                            {
                                                e.Description = "Greška nedovoljna količina";
                                                _loc.Tag = (int)_loc.Tag + 1;
                                                return false;
                                            }
                                            else
                                            {
                                                return true;
                                            }
                                        }
                                            ), _loc);

                                        _dspoartorg.Validate();
                                    }
                                    
                                }
                                else
                                {
                                    if (_dspoartorg != null)
                                    {

                                        ValidationRuleArgs _loc = new ValidationRuleArgs("Kolicina");
                                        _loc.Tag = 0;
                                        _dspoartorg.AddValidationRuleHandler((delegate(object target, ValidationRuleArgs e)
                                        {
                                            if ((int)e.Tag == 0)
                                            {
                                                e.Description = "Greška nedovoljna količina";
                                                _loc.Tag = (int)_loc.Tag + 1;
                                                return false;
                                            }
                                            else
                                            {
                                                return true;
                                            }
                                        }), _loc);
                                        _dspoartorg.Validate();
                                        //_dspoartorg.AddValidationRuleHandler((delegate(object target, ValidationRuleArgs e) { e.Description = "Greška nedovoljna količina"; return false; }), new ValidationRuleArgs("Kolicina"));
                                        //_dspoartorg.Validate();
                                    }
                                }
                            }
                            
                    }
                    result = false;
                }
                
            }
            else
            {
                return result;
            }
            return result;
        }

        private static readonly int[] _arr = new int[]  {10,
                                                         13,
                                                         26,
                                                         28,
                                                         30,
                                                         32,
                                                         34,
                                                         37,
                                                         39,
                                                         42,
                                                         46,
            5,
            2
                                                        };

        internal void KopiranjeStavkiCore(Dokument _entity,DateTime _dateui)
        {
            if (_entity.IDStatus == 0 && Array.IndexOf(_arr, _entity.IDDokumentTip) != -1 )
                ShowModalSearch(new Infrastructure.Interface.EventArgs<Dokument, bool,DateTime>(_entity, _changed || _entity.ID != 0,_dateui),
                                typeof (KopiranjeDokumentaView), null);
            
        }


        //public void ShowModalSearch(object EntityToSearch, Type SearcherClass, object Parameters, string pozvano)
        //{

        //   _pozvano = pozvano;
        //    ShowModalSearch(EntityToSearch, SearcherClass, Parameters);
        //   _pozvano = "None";

        //}
        //public void ShowModalSearch(object EntityToSearch, string SearcherClass, object Parameters, string pozvano)
        //{


        //    Type _gettype = null;
        //    _gettype = (Type)WorkItem.RootWorkItem.Items.Get(SearcherClass);
        //    _pozvano = pozvano;
        //    if (_gettype != null)
        //    {
        //        ShowModalSearch(EntityToSearch, _gettype, Parameters);
        //        _pozvano = "None";
        //    }

        //}

        //public void OpenEditorNewOrEditinParent(object Entity)
        //{
        //    WorkItem.EventTopics[EventTopicNames.OpenCreateView].Fire(this.View, new EventArgs<object, object, object, object, WorkItem>(null, Entity, null, null, WorkItem.Parent), WorkItem, PublicationScope.Global);
        //}

        //public override void OnViewReady()
        //{
        //    base.OnViewReady();
        //}
        readonly BaseOtvaranjeIzvjestaja _tmpReportOpen = new BaseOtvaranjeIzvjestaja();
            public void ShowReportForDokumentTip(Dokument _entity)
        {
          _tmpReportOpen.ShowReportForDokumentTip("BaseEditorPresenter",_entity, WorkItem);
        }
    
      public virtual void KopiranjeStavaka()
      {
          return;
      }
        //if (_entity == null) return;
           //if (_entity.ID == 0)
           //{
           //    return;
           //}
           //DevExpress.XtraReports.UI.XtraReport report;
           //ReportSelectorFrm _tmpfrm = new ReportSelectorFrm();
           //System.Collections.ArrayList _tmpList = new System.Collections.ArrayList();
           //switch (_entity.IDDokumentTip)
           //{
           //    case (int)DokumentTipList.Međuskladišnica_Izdana_Robno:
           //        report = new MeduskladisnicaIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Međuskladišnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Međuskladišnica_Izdana_Storno:
           //        report = new MeduskladisnicaStornoIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Međuskladišnica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Međuskladišnica_Primljena_Robno:
           //        report = new MeduskladisnicaPrijemIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Međuskladišnica prijem {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Međuskladišnica_prijem_Storno:
           //        report = new MeduskladisnicaPrijemStornoIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Međuskladišnica prijem storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Narudžba:
           //        _tmpfrm = new ReportSelectorFrm();
           //        //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
           //        _tmpList = new System.Collections.ArrayList();
           //        //_tmpdict.Add(1, "Prijemni list storno");
           //        //_tmpdict.Add(0, "Povrat robe");
           //        _tmpList.Add("Narudžbenica s cijenom");
           //        _tmpList.Add("Narudžbenica");
           //        _tmpfrm.LBIzabir.DataSource = _tmpList;
           //        _tmpfrm.LBIzabir.SelectedIndex = 0;
           //        //_tmpfrm.LBIzabir.DisplayMember("Value");
           //        if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           //        {
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Narudžbenica")
           //            {
           //                report = new NarudzbenicaIspis(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Narudžbenica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //            }
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Narudžbenica s cijenom")
           //            {

           //                report = new NarudzbenicaIspis2(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Narudžbenica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);


           //            }

           //        }
           //        break;
           //    case (int)DokumentTipList.Narudžba_storno:
           //        _tmpfrm = new ReportSelectorFrm();
           //        //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
           //        _tmpList = new System.Collections.ArrayList();
           //        //_tmpdict.Add(1, "Prijemni list storno");
           //        //_tmpdict.Add(0, "Povrat robe");
           //        _tmpList.Add("Narudžbenica s cijenom");
           //        _tmpList.Add("Narudžbenica");
           //        _tmpfrm.LBIzabir.DataSource = _tmpList;
           //        _tmpfrm.LBIzabir.SelectedIndex = 0;
           //        //_tmpfrm.LBIzabir.DisplayMember("Value");
           //        if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           //        {
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Narudžbenica")
           //            {
           //                report = new NarudzbenicaIspis(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Narudžbenica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //            }
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Narudžbenica s cijenom")
           //            {

           //                report = new NarudzbenicaIspis2(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Narudžbenica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);


           //            }

           //        }
           //        break;
           //    case (int)DokumentTipList.Otkaz_rezervacije:
           //        //EditorClass = typeof(RezervacijaView);
           //        break;
           //    case (int)DokumentTipList.Otpremnica:
           //        _tmpfrm = new ReportSelectorFrm();
           //        //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
           //        _tmpList = new System.Collections.ArrayList();
           //        //_tmpdict.Add(1, "Prijemni list storno");
           //        //_tmpdict.Add(0, "Povrat robe");
           //        _tmpList.Add("Otpremnica");
           //        _tmpList.Add("Otpremnica s cijenom");
           //        _tmpfrm.LBIzabir.DataSource = _tmpList;
           //        _tmpfrm.LBIzabir.SelectedIndex = 0;
           //        //_tmpfrm.LBIzabir.DisplayMember("Value");
           //        if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           //        {
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Otpremnica s cijenom")
           //            {
           //                report = new OtpremnicaIspis(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Otpremnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //            }
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Otpremnica")
           //            {

           //                report = new OtpremnicaIspisKol(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Otpremnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);

           //            }

           //        }

           //        break;
           //    case (int)DokumentTipList.Otpremnica_Storno:
           //        _tmpfrm = new ReportSelectorFrm();
           //        //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
           //        _tmpList = new System.Collections.ArrayList();
           //        //_tmpdict.Add(1, "Prijemni list storno");
           //        //_tmpdict.Add(0, "Povrat robe");
           //        _tmpList.Add("Otpremnica");
           //        _tmpList.Add("Otpremnica s cijenom");
           //        _tmpfrm.LBIzabir.DataSource = _tmpList;
           //        _tmpfrm.LBIzabir.SelectedIndex = 0;
           //        //_tmpfrm.LBIzabir.DisplayMember("Value");
           //        if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           //        {
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Otpremnica s cijenom")
           //            {

           //                report = new OtpremnicaIspisStorno(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Otpremnica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //            }
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Otpremnica")
           //            {


           //                report = new OtpremnicaIspisKolStorno(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Otpremnica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //            }

           //        }

           //        break;

           //    case (int)DokumentTipList.Početno_stanje:
           //        report = new Pocetnostanje(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Početno stanje{0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Početno_stanje_storno:
           //        break;
           //    case (int)DokumentTipList.Prijemni_list:
           //        if (_entity.IDValute == 1 || _entity.IDValute == null)
           //        {
           //            report = new PrijemniList(_entity);

           //        }
           //        else
           //        {
           //            report = new PrijemniListValuti(_entity);
           //        }
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Prijemni list{0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;

           //    case (int)DokumentTipList.Prijemni_list_Storno:
           //        _tmpfrm = new ReportSelectorFrm();
           //        //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
           //        _tmpList = new System.Collections.ArrayList();
           //        //_tmpdict.Add(1, "Prijemni list storno");
           //        //_tmpdict.Add(0, "Povrat robe");
           //        _tmpList.Add("Prijemni list strono");
           //        _tmpList.Add("Povrat robe");
           //        _tmpfrm.LBIzabir.DataSource = _tmpList;
           //        _tmpfrm.LBIzabir.SelectedIndex = 0;
           //        //_tmpfrm.LBIzabir.DisplayMember("Value");
           //        if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           //        {
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Prijemni list strono")
           //            {
           //                if (_entity.IDValute == 1 || _entity.IDValute == null)
           //                {
           //                    report = new PrijemniListStorno(_entity);

           //                }
           //                else
           //                {
           //                    report = new PrijemniListValutiStorno(_entity);
           //                }
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Prijemni list {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //            }
           //            if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Povrat robe")
           //            {

           //                report = new PovratRobe(_entity);
           //                WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Povrat robe {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);


           //            }

           //        }

           //        break;

           //    case (int)DokumentTipList.Rezervacija:
           //        //EditorClass = typeof(RezervacijaView);
           //        break;
           //    case (int)DokumentTipList.Zapisnik_o_promjeni_cijene:
           //        report = new rptXtraPromjenaCijene(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Promjena cijene{0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Racun:
           //        report = new RacunOtpremnica(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Racun_storno:
           //        report = new RacunOtpremnicaOK(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun-OK {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Racun_otpremnica:
           //        report = new RacunOtpremnica(_entity);
           //        // report = new rptXtraPonuda(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun otpremnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Racun_otpremnica_storno:
           //        report = new RacunOtpremnicaOK(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun-otpremnica OK {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Ponuda:
           //        report = new RacunOtpremnica(_entity);
           //        report.Name = "PonudaIspis";
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Ponuda {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Ponuda_storno:
           //        report = new RacunOtpremnica(_entity);
           //        report.Name = "PonudaIspis";
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Storno ponude {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Predračun:
           //        report = new RacunOtpremnica(_entity);
           //        report.Name = "PredračunIspis";
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Predračun {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Predračun_storno:
           //        report = new RacunOtpremnica(_entity);
           //        report.Name = "PredračunStornoIspis";
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Storno predračuna {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Racun_tranzitni:
           //        report = new RacunOtpremnica(_entity);
           //        report.Name = "RačuntranzitniIspis";
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun tranzitni {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Racun_tranzitni_storno:
           //        report = new RacunOtpremnicaOK(_entity);
           //        report.Name = "RačuntranzitniStornoIspis";
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun tranzitni storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Izdatnica_storno:
           //        report = new IzdatnicaIspisStorno(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Izdatnica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Izdatnica:
           //        report = new IzdatnicaIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Izdatnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Racun_usluga:
           //        report = new RacunUsluga(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun usluga {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Racun_usluga_storno:
           //        report = new RacunUslugaStorno(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun usluga storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Račun_MP:
           //        report = new RacunMPIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun maloprodajni {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Račun_MP_storno:
           //        report = new RacunMPStornoIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun maloprodajni storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Revers:
           //        report = new ReversIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Revers {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    case (int)DokumentTipList.Povrat_reversa:
           //        report = new ReversIspis(_entity);
           //        WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Povrat reversa {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
           //        break;
           //    default:
           //        break;

           //}


    }

      //  #endregion

}
